package www.lagou.dao;

import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;
import www.lagou.entity.Dept;
import www.lagou.utils.DruidUtils;

import java.sql.SQLException;

/**
 * 部门表操作
 *
 * @author Shuxian Huang
 */
public class DeptDao {

    /**
     * 通过ID查询对应的部门信息
     * @param id
     * @return
     * @throws SQLException
     */
    public Dept findDeptById(Integer id) throws SQLException {

        //1、创建QueryRunner
        QueryRunner qr = new QueryRunner(DruidUtils.getDataSource());

        //2、sql语句
        String sql = "select * from dept where id = ?";

        //3、执行查询
        return qr.query(sql, new BeanHandler<Dept>(Dept.class), id);
    }
}
